/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ditt.swing;

import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.*;

/**
 *
 * @author attobra
 */
public class CarnetAdresse {
    public static void main (String[] args){
        
        JFrame fenetre = new JFrame("Carnet d'adresse");
        //fenetre.setLayout(new BorderLayout(5,5));
        String[] entete = {"Titre","Nom","Prenom","Adresse"};
       final  DefaultTableModel model = new DefaultTableModel(entete, 0);
        
         JTable grilleDonnees = new javax.swing.JTable(model);
         
        fenetre.add(new JScrollPane(grilleDonnees));
        
        int raccourci = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
        
        JMenuItem menuNouveau = new javax.swing.JMenuItem("Nouveau", 'N');
        menuNouveau.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, raccourci));
        
        menuNouveau.addActionListener( new ActionListener(){
            public void actionPerformed(ActionEvent e){
                Contact panneauConctact = new Contact();
                int reponse = JOptionPane.showConfirmDialog(null, panneauConctact, "Contact", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (reponse == JOptionPane.OK_OPTION ){
                    model.addRow(new String[]{panneauConctact.getTitre(),panneauConctact.getNom(),panneauConctact.getPrenom(),panneauConctact.getAdresse()});
                 } 
             }
            
        });
        
        JMenuItem menuQuitter = new javax.swing.JMenuItem("Quitter", 'Q');
         menuQuitter.addActionListener( new ActionListener(){
            public void actionPerformed(ActionEvent e){
               System.exit(0);
            }
            
        });
         
         JMenu menuFichier = new JMenu("Fichier");
         menuFichier.add(menuNouveau);
         menuFichier.add(menuQuitter);
         
         JMenuBar menuBar = new javax.swing.JMenuBar();
         menuBar.add(menuFichier);
        
        
        
        fenetre.add(menuBar, BorderLayout.NORTH);
        
        //fenetre.pack();
        fenetre.setSize(300,200);
        
        fenetre.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        
        fenetre.setVisible(true);
    }
    
}
